import myAxios from "../index";

export default {
  // 查询所有角色
  findAll: () =>
    myAxios<Result<SysRole[]>>({
      url: "/admin/system/sysRole/findAll",
      method: "get",
    }),

  // 根据ID查询角色
  findById: (id: number) =>
    myAxios<Result<SysRole>>({
      url: `/admin/system/sysRole/findById/${id}`,
      method: "get",
    }),

  // 新增角色
  add: (data: SysRole) =>
    myAxios<Result<void>>({
      url: "/admin/system/sysRole/add",
      method: "post",
      data,
    }),

  // 更新角色
  update: (data: SysRole) =>
    myAxios<Result<void>>({
      url: "/admin/system/sysRole/update",
      method: "put",
      data,
    }),

  // 分页查询角色
  page: (data: SysRole) =>
    myAxios<Result<PageResult<SysRole>>>({
      url: "/admin/system/sysRole/page",
      method: "post",
      data,
    }),

  // 删除角色
  delete: (id: number) =>
    myAxios<Result<void>>({
      url: `/admin/system/sysRole/delete/${id}`,
      method: "delete",
    }),

  // 批量删除角色
  batchDelete: (ids: number[]) =>
    myAxios<Result<void>>({
      url: "/admin/system/sysRole/batchDelete",
      method: "post",
      data: ids,
    }),

  // 获取角色菜单权限
  getMenusByRoleId: (roleId: string) =>
    myAxios<Result<SysMenu[]>>({
      url: `/admin/system/sysRole/getMenusByRoleId/${roleId}`,
      method: "get",
    }),

  // 为角色分配菜单权限
  assignMenus: (roleId: string, menuIds: string[]) =>
    myAxios<Result<void>>({
      url: "/admin/system/sysRole/assignMenus",
      method: "post",
      params: { roleId },
      data: menuIds,
    }),
};
